package 多无人机架次;

import GA_Test.GAData;

import java.util.*;

public class Distance {


    public static Integer wDistance1(int i,ArrayList<Integer> a){ //计算 集合a 中 距离i 最近的 点

        HashMap<Integer,Double> map1 = new HashMap<>();
      for (int j = 0;j<a.size();j++){
          int k = a.get(j);
          map1.put(k, GAData.disCollection[i][k]);
      }
        List<Map.Entry<Integer,Double>> list = new ArrayList<>(map1.entrySet()); //将map的entryset放入list集合

        Collections.sort(list,new Comparator<Map.Entry<Integer, Double>>()
        {
            public int compare(Map.Entry<Integer,Double> o1, Map.Entry<Integer,Double> o2) {
                return o1.getValue().compareTo(o2.getValue()); //重写排序规则，小于0表示升序，大于0表示降序
            }
        });
        return  list.get(0).getKey();

    }
    public static Integer wDistance2(int i,ArrayList<Integer> a){

        HashMap<Integer,Double> map1 = new HashMap<>();
        for (int j = 0;j<a.size();j++){
            int k = a.get(j);
            map1.put(k, GAData.disCollection[i][k]);
        }
        List<Map.Entry<Integer,Double>> list = new ArrayList<>(map1.entrySet()); //将map的entryset放入list集合

        Collections.sort(list,new Comparator<Map.Entry<Integer, Double>>()
        {
            public int compare(Map.Entry<Integer,Double> o1, Map.Entry<Integer,Double> o2) {
                return o1.getValue().compareTo(o2.getValue()); //重写排序规则，小于0表示升序，大于0表示降序
            }
        });
        return  list.get(1).getKey();

    }
    public static ArrayList<Integer> sProduce(ArrayList<Integer> a,ArrayList<Integer> b){
        //Double[][] juli = ReadDate.countDistance();
        //Node[] nodee = ReadDate.ReadNode();
        ArrayList<Integer> s = new ArrayList<>();
       //首先取出 w中 m满足的那些点   然后将这些点与RU内最后一个点的距离进行排序
        Integer bLast = b.get(b.size()-1);//b 是RU集合    a是未访问节点 集你信不信
        // if（当前点的载重满足要求  当前点的距离满足要求，则将当前点 加入s
        HashMap<Integer,Double> smap = new HashMap<>();

        for (int j = 0;j<a.size();j++){
            int k = a.get(j);
               smap.put(k, GAData.disCollection[bLast][k]);

       }
        List<Map.Entry<Integer,Double>> list = new ArrayList<>(smap.entrySet()); //将map的entryset放入list集合
        Collections.sort(list,new Comparator<Map.Entry<Integer, Double>>()
        {
            public int compare(Map.Entry<Integer,Double> o1, Map.Entry<Integer,Double> o2) {
                return o1.getValue().compareTo(o2.getValue()); //重写排序规则，小于0表示升序，大于0表示降序
            }
        });
        for(Map.Entry<Integer,Double> node : list){
             s.add(node.getKey());
        }
        return s;
    }
    public static double sumUd(ArrayList<Integer> a){


        double Ud = 0.00;
        for (int i = 0;i<a.size()-1;i++){
             Ud += GAData.disCollection[a.get(i)][a.get(i+1)];
        }
        return Ud;
    }
}
